package com.gtp.kafka.demo;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.ListConsumerGroupOffsetsResult;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;

public class Demo1 {

	//可列出消费组offset,那总offset咋看?
	public static void main(String[] args) throws Exception{
		
		 Properties props = new Properties();
	     props.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "10.103.27.42:9091");
		
		AdminClient ac = AdminClient.create(props);
		
//		Collection<String> topicNames=new ArrayList<>();
//		topicNames.add("radarlog");
//		DescribeTopicsResult tr = ac.describeTopics(topicNames);
//		Map<String, TopicDescription> tt = tr.all().get();
		
		ListConsumerGroupOffsetsResult result = ac.listConsumerGroupOffsets("apmEsGrouptest");
		
		Map<TopicPartition, OffsetAndMetadata> consumedOffsets  = result.partitionsToOffsetAndMetadata().get();
		
		Iterator<TopicPartition> it = consumedOffsets.keySet().iterator();
		while(it.hasNext()){
			TopicPartition k = it.next();
			OffsetAndMetadata v = consumedOffsets.get(k);
			//topic-partition-offset
			System.out.println(k+">"+v.offset());
		}
	}
}
